//
//  AppDelegate+TDBaseDateCheck.m
//  TBRentClient
//
//  Created by tonbright on 2018/6/19.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "AppDelegate+TDBaseDateCheck.h"
#import "NetWorkRequest.h"
#import "TDChooseCarModel.h"//选择车辆的信息---------------
#import "NSString+MD5Addition.h"
#import <YYModel.h>
@implementation AppDelegate (TDBaseDateCheck) 


// MARK: - 校验基础数据-------------
- (void)checkBaseData {
    __weak typeof(self) weakSelf = self;
    [NetWorkRequest getNetRequestData:CheckBasicMessageInfo parmeters:nil response:^(NSDictionary *response) {
        //        data是一个数组----------------我真是个智障额....
        if (response) {
            NSArray *tmpArray = response[@"data"];
            NSString *getBasicMessage = tmpArray.firstObject[@"basedatamd5"];
            NSString *localBasicMessageMD5Str = [HelpObject getDocumentDicStrPath:kBasicMD5MessageFilePath];
            if ([localBasicMessageMD5Str isEqualToString:getBasicMessage]) {
                return;
            }
            //其他情况下获取网路数据-------
            [weakSelf loadNetData:getBasicMessage];
        }
        
        
    } netError:^(NSError *error) {
        
    }];
}


// MARK: - 获取基础网络数据-----
- (void)loadNetData:(NSString *)basicMessageMD5 {
    [NetWorkRequest getNetRequestData:GetBasicMessageInfo parmeters:nil response:^(NSDictionary *response) {
        if (response) {
            [HelpObject writeToDocument:response strPath:kBasicMessageFilePath];
            [HelpObject writeToDocument:basicMessageMD5 strPath:kBasicMD5MessageFilePath];
            [AppSetting shareAppSetting].topcompanyid = response[@"data"][@"config"][@"topcompanyid"];
        }
        
//        //        data是一个数组----------------我真是个智障额....
//        NSArray *tmpDataArray = response[@"data"];
//        NSArray *tmpCarbrandsArray = tmpDataArray.firstObject[@"carbrands"];
//        NSArray *tmpHotCarsArray = tmpDataArray.firstObject[@"hotcars"];
//        NSMutableArray *totalArray = [NSArray yy_modelArrayWithClass:[TDChooseCarModel class] json:tmpCarbrandsArray].mutableCopy;
//        NSMutableArray *sectionTitleArray = [NSMutableArray array];
//        for (TDChooseCarModel *totalModel in totalArray) {
//            [sectionTitleArray addObject:totalModel.sortby];
//        }
//        NSMutableArray *hotCarsArray = [NSArray yy_modelArrayWithClass:[TDChooseCarBrandModel class] json:tmpHotCarsArray].mutableCopy;
//        NSMutableArray *originHotCarsArray = [NSArray yy_modelArrayWithClass:[TDChooseCarBrandModel class] json:tmpHotCarsArray].mutableCopy;
        
    } netError:^(NSError *error) {
        
    }];
}

@end
